const proxy = require("koa-proxy");
const convert = require("koa-convert");
const Router = require("koa-router");
const config = require("../../config/env");

// import proxy from "koa-proxy";
// import convert from "koa-convert";
// import Router from "koa-router";
// import config from "../../config/env";
const devStaticFileRouter = new Router();

devStaticFileRouter.get('/static/*.hot-update.*', convert(proxy({
  host: `http://${config.dev_hot_server_host}:${config.dev_hot_server_port}`,
  map: (path) => {
    return path;
  },
})));

devStaticFileRouter.get('/static/(js|css)/*', convert(proxy({
  host: `http://${config.dev_hot_server_host}:${config.dev_hot_server_port}`,
  map: (path) => {
    return path;
  },
})));

module.exports = (app) => {
  app.use(devStaticFileRouter.routes()).use(devStaticFileRouter.allowedMethods());
};
